
/****
 * Copyright (C) 2006 dNux Team
 *                                                            ****
 * This program is free software; you can redistribute it and/or *
 * modify under the terms of the GNU General Public License as   *
 * published by the Free Software Foundation;                    *
 * either version 2 of the License.                              *
 *                                                               *
 * This program is distributed in the hope that it will be       *
 * useful, but WITHOUT ANY WARRANTY; without even the implied    *
 * warranty of without even the implied waranty of               *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.          *
 * See the GNU General Public License for more details.          *
 *                                                               *
 * You should have received a copy of the                        *
 * GNU General Public License                                    *
 * along with this program; if not, write to the                 *
 * Free Software Foundation, Inc.,                               *
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. *
 *                                                               *
 ****                                                         ****/

#include <dpkg.h>

static d_bool_t create=d_false;
static d_bool_t install=d_false;
static char*    file=NULL;
static char*    name=NULL;
static char*    version=NULL;
static char*    install_prefix=NULL;
static char*    data_dir=NULL;

static d_cmdline_t cmdline[] = {
  {"--create", "-c", "create", D_CMDLINE_ARG_NONE, &create, NULL},
  {"--install", "-i", "install", D_CMDLINE_ARG_NONE, &install, NULL},
  {"--file", "-f", "filename", D_CMDLINE_ARG_STRING, &file, NULL},
  {"--name", "-n", "name", D_CMDLINE_ARG_STRING, &name, NULL},
  {"--version", "-v", "version", D_CMDLINE_ARG_STRING, &version, NULL},
  {"--install-prefix", "-prefix", "prefix", D_CMDLINE_ARG_STRING, &install_prefix, NULL},
  {"--data-dir", "-d", "dir", D_CMDLINE_ARG_STRING, &data_dir, NULL},
  {NULL},
};


int
main (int argc, char **argv)
{
  d_error_t *error=NULL;
  d_pkg_t *pkg=NULL;

  d_cmdline_parse(cmdline, argc, argv);
  
  if (! name) return EXIT_FAILURE;
  if (! file) return EXIT_FAILURE;
  if (! version) return EXIT_FAILURE;

  pkg = d_pkg_new();
  d_pkg_set_name(pkg, name);
  d_pkg_set_version(pkg, version);
  d_pkg_set_file(pkg, file);
  if (install_prefix) d_pkg_set_install_prefix(pkg, install_prefix);
  
  if (create) d_pkg_create(pkg, data_dir, &error);
  if (install) d_pkg_install(pkg, &error);

  if (error) {
    d_error_display(error);
    d_error_free(&error);
  }
    
  d_pkg_free(&pkg);    
  return EXIT_SUCCESS;
}
